package com.qf.demo05.controller;

import com.baomidou.kaptcha.Kaptcha;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RestController

public class KaptchaController {

    @Autowired
    private Kaptcha kaptcha;

    @GetMapping("/captcha")
    public void render() {
        kaptcha.render();  // 生成验证码图片，并返回
    }

    @GetMapping("/valid")
    public void validDefaultTime(@RequestParam String code) {
        //default timeout 900 seconds
        kaptcha.validate(code);
    }

    @GetMapping("/validTime")
    public void validCustomTime(@RequestParam String code) {
        kaptcha.validate(code, 1);
    }
}


